package com.xxxy.controller;

import com.xxxy.commonResult.CommonResult;
import com.xxxy.dao.StudentAnswerDao;
import com.xxxy.log.Log;
import com.xxxy.model.StudentAnswer;
import com.xxxy.response.StudentAnswerResponse;
import com.xxxy.response.StudentPaperResponse;
import com.xxxy.service.StudentAnswerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author sjh
 * @date 2022/3/5 13:37
 */
@RestController
@Api(tags = "学生答案管理")
@RequestMapping("/studentAnswer")
public class StudentAnswerController {

    @Autowired
    StudentAnswerService studentAnswerService;

    @Log(module = "学生答案管理", description = "学生交卷")
    @PostMapping(value = "/putPaper")
    @ApiOperation(value = "学生交卷")
    @Async("threadPoolTaskExecutor")
    public CommonResult<Boolean> putPaper(@ApiParam("试卷id") @RequestParam Integer examId,
                                          @ApiParam("学生账号") @RequestParam String StudentAccount,
                                          @ApiParam("教学班级") @RequestParam Integer teachingClassId,
                                          @ApiParam("答题情况") @RequestParam String answerSituation) {
        return CommonResult.success(studentAnswerService.putPaper(examId, StudentAccount, teachingClassId, answerSituation));
    }

    @Log(module = "学生答案管理", description = "书籍图片上传")
    @PostMapping("/uploadImage")
    @ApiOperation(value = "书籍图片上传")
    public CommonResult<String> uploadImage(@ApiParam("文件") @RequestParam MultipartFile multipartFile) throws IOException {
        return CommonResult.success(studentAnswerService.imageUpload(multipartFile));
    }

    @Log(module = "学生答案管理", description = "班级/学科成绩分析")
    @GetMapping(value = "/grade/class")
    @ApiOperation(value = "班级/学科成绩分析")
    public CommonResult<Map<String, String>> gradeClass(@ApiParam("试卷id") @RequestParam(required = false) Integer examId,
                                                        @ApiParam("教学班级") @RequestParam(required = false) String teachingClassIdArry) {
        return CommonResult.success(studentAnswerService.gradeDistribution(teachingClassIdArry, examId));
    }

    @Log(module = "学生答案管理", description = "学生自查分数")
    @GetMapping(value = "/grade/student")
    @ApiOperation(value = "学生自查分数")
    public CommonResult<StudentAnswerResponse> gradeStudent(@ApiParam("学生账号") @RequestParam String studentAccount,
                                                            @ApiParam("试卷id") @RequestParam Integer examId) {
        return CommonResult.success(studentAnswerService.getScoreStudent(studentAccount, examId));
    }

    @Log(module = "学生答案管理", description = "学生获取考试")
    @GetMapping(value = "/getExam")
    @ApiOperation(value = "学生获取考试")
    public CommonResult<List<StudentPaperResponse>> examStudent(@ApiParam("学生账号") @RequestParam String studentAccount) {
        return CommonResult.success(studentAnswerService.getExamPaper(studentAccount));
    }
}
